import java.util.Arrays;
import java.util.Scanner;

/**
 * @ClassName ArrayAddTest
 * @Description TODO
 * @Author lwj
 * @Date 2021/3/7 22:08
 * @Version 1.0
 */
public class ArrayAddTest {
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3};
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要添加的数组元素：");
        int i = scanner.nextInt();
        arr1 = new int[]{1, 2, 3, i};
        System.out.println("添加成功，是否继续？y/n");
        String next = scanner.next();
        int[] arr2 = new int[0];
        if ("y".equals(next) || "Y".equals(next)) {
            for (; ; ) {
                System.out.println("请输入需要添加的数组元素：");
                int i1 = scanner.nextInt();
                arr2 = new int[arr1.length + 1];
                for (int j = 0; j < arr1.length ; j ++) {
                    arr2[j] = arr1[j];
                }
                arr2[arr1.length] = i1;
                System.out.println("添加成功，是否继续？y/n");
                next = scanner.next();
                if ("y".equals(next) || "Y".equals(next)) {
                    continue;
                } 
                break;
            }
        }
        System.out.println("当前数组为：" + Arrays.toString(arr2));
    }
}
